package Data;

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class GeoCoord {

    private double latitude;
    private double longitude;
    private NumberFormat format = new DecimalFormat("+0.0############;-0.0#############");

    public GeoCoord(double latitude, double longitude) {
        this.latitude = latitude;
        this.longitude = longitude;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        if (latitude > -180 && latitude < 180) {
            this.latitude = latitude;
        } else {
            throw new IllegalArgumentException("latitude must be between -180 and 180");
        }
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        if (longitude > -90 && longitude < 90) {
            this.longitude = longitude;
        } else {
            throw new IllegalArgumentException("longitude must be between -90 and 90");
        }
    }

    @Override
    public String toString() {
        return format.format(latitude) + format.format(longitude);
    }
}
